Don't keep the filesystem model alive while querying files
authorBenjamin Otte <otte@gnome.org>
Mon, 2 Nov 2009 18:49:11 +0000 (19:49 +0100)
committerBenjamin Otte <otte@gnome.org>
Mon, 2 Nov 2009 19:11:09 +0000 (20:11 +0100)
This allows disposing of the filesystemmodel while the file enumeration
is still happening.
As the filechooser does not disconnect its signals because it assumes it
is the only owner of the model, this also prevents a SEGV when emitting
the "load-finished" signal in that case.

gtk/gtkfilesystemmodel.c

index 095969bdc672e9847e99a0eba780cb63a43d423b..c73ebb8fa06e05f35f7167e3aadd913bb05dfee4 100644 (file)
@@ -1113,24 +1113,25 @@ gtk_file_system_model_got_files (GObject *object, GAsyncResult *res, gpointer da
     }
   else
     {
-      g_file_enumerator_close_async (enumerator, 
-                                     IO_PRIORITY,
-                                     model->cancellable,
-                                     gtk_file_system_model_closed_enumerator,
-                                     model);
-      if (model->dir_thaw_source != 0)
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
         {
-          g_source_remove (model->dir_thaw_source);
-          model->dir_thaw_source = 0;
-          _gtk_file_system_model_thaw_updates (model);
-        }
+          g_file_enumerator_close_async (enumerator,
+                                         IO_PRIORITY,
+                                         model->cancellable,
+                                         gtk_file_system_model_closed_enumerator,
+                                         NULL);
+          if (model->dir_thaw_source != 0)
+            {
+              g_source_remove (model->dir_thaw_source);
+              model->dir_thaw_source = 0;
+              _gtk_file_system_model_thaw_updates (model);
+            }
 
-      g_signal_emit (model, file_system_model_signals[FINISHED_LOADING], 0, error);
+          g_signal_emit (model, file_system_model_signals[FINISHED_LOADING], 0, error);
+        }
 
       if (error)
         g_error_free (error);
-
-      g_object_unref (model);
     }
 
   gdk_threads_leave ();
@@ -1270,7 +1271,6 @@ gtk_file_system_model_set_directory (GtkFileSystemModel *model,
   model->dir = g_object_ref (dir);
   model->attributes = g_strdup (attributes);
 
-  g_object_ref (model);
   g_file_enumerate_children_async (model->dir,
                                    attributes,
                                    G_FILE_QUERY_INFO_NONE,